package com.pool.store.gdata;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;

import android.util.Log;

import com.pool.common.Record;

/**
 * @author claveld@gmail.com (David Clavel)
 */
public class RecordGDataFactory implements GDataFactory<Record> {

  public Record createFrom(Map<String, String> values) {
    
    Log.i("MAP", "Printing:");
    for (Map.Entry<String, String> entry : values.entrySet()) {
      Log.i("MAP", "key=" + entry.getKey() + " value=" + entry.getValue());
    }
    
    String timestamp = values.get("Timestamp");
    String player = values.get("Player");
    String shootId = values.get("Shoot");
    int remainingBalls = Integer.parseInt(values.get("Remaining balls"));
    
    SimpleDateFormat timestampFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    String id = "-1";
    try {
      id = Long.toString(timestampFormat.parse(timestamp).getTime());
    } catch (ParseException e) {
    }
    
    return new Record(id, timestamp, player, shootId, remainingBalls);
  }
}
